// 导入axios网络请求库
import axios from "axios";
// 导入接口地址
import api from "./api_address";
// 创建实例时配置默认值
const http = axios.create({ baseURL: "http://localhost:3000" });
// const http = axios.create({ baseURL: "http://81.71.152.175:3001" });

http.interceptors.response.use(
    function (response) {
        // 直接获取响应数据中的data
        return response.data;
    },
    function (error) {
        return Promise.reject(error);
    }
);
//搜索
export const getSearch = (data = {}) => {
    return http.get(api.get_search, { params: data });
};
//登录
export const myLogin = (data = {}) => {
    return http.post(api.login, data);
};
//获取验证码
export const sendCode = (data = {}) => {
    return http.get(api.sendcode, { params: data });
};
//注册
export const myRegister = (data = {}) => {
    return http.post(api.register, data);
};
//首页商品列表
export const indexList = (data = {}) => {
    return http.get(api.indexlist, data);
};
//首页轮播图列表
export const bannerList = (data = {}) => {
    return http.get(api.get_banner, data);
};
//分类页商品分类
export const getClassify = (data = {}) => {
    return http.get(api.classify, { params: data });
};
//商品详情
export const getDetail = (data = {}) => {
    return http.get(api.productdetail, { params: data });
};
//上传头像
export const upLoadImg = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.uploadImg, data, option);
};
//保存头像
export const saveImg = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.saveImg, data, option);
};
//删除头像的接口
export const deleteImg = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.deleteImg, data, option);
};
//获取用户头像和昵称接口
export const getAvatorNickName = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.get(api.getAvatorNickName, { params: data });
};
//获取用户id
export const getUserId = (data = {}) => {
    return http.get(api.get_id, { params: data });
};
//加入购物车
export const joinCart = (data = {}) => {
    return http.get(api.join_cart, { params: data });
};
//获取购物车信息
export const getCart = (data = {}) => {
    return http.get(api.get_cart, { params: data });
};
//删除购物车信息
export const deleteCart = (data = {}) => {
    return http.get(api.delete_cart, { params: data });
};
//添加订单
export const getOrder = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.add_order, data, option);
};
//用户订单
export const getUserOrder = (data = {}) => {
    return http.get(api.get_order, { params: data });
};
//添加地址
export const addAddress = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.add_address, data, option);
};
//地址列表
export const getUserAddress = (data = {}) => {
    return http.get(api.get_address, { params: data });
};
//获取个人资料
export const getUserPerson = (data = {}) => {
    return http.get(api.get_person, { params: data });
};
//修改个人资料
export const modifyUserPerson = (data = {}) => {
    return http.get(api.modify_person, { params: data });
};
//判断用户是否收藏
export const getIsCollect = (data = {}) => {
    return http.get(api.get_iscollect, { params: data });
};
//添加商品收藏
export const addCollect = (data = {}, option = { headers: "application/x-www-form-urlencoded" }) => {
    return http.post(api.add_collect, data, option);
};
//取消商品收藏
export const deleteCollect = (data = {}) => {
    return http.get(api.delete_collect, { params: data });
};
//获取收藏列表
export const getCollectList = (data = {}) => {
    return http.get(api.get_collect_list, { params: data });
};
//获取待收货商品
export const getNotReceived = (data = {}) => {
    return http.get(api.get_not_received, { params: data });
};
//获取已收货商品
export const getToReceived = (data = {}) => {
    return http.get(api.get_to_received, { params: data });
};
//修改待收货为已收货
export const modifyReceivedState = (data = {}) => {
    return http.get(api.modify_received_state, { params: data });
};
